import Vue from "vue";
import store from "@/store"

const moudle = {
  //#region 生产信息
  生产信息: "D4D03D9A-B28F-49E9-946B-FAF8F0DCE351",
  物料管理: "9150DA3F-92AF-43D3-882A-3410640288B0",
  物料同步: "3A00CC4E-F1B7-432B-93B2-A273A9B0344B",
  工序管理: "0266879b-f488-413a-9b82-a656f45fe7d2",
  工艺管理: "f746e139-f4bc-4c2c-bd78-df2ad72cf5dc",
  //#endregion
};
Vue.directive("hasPermission", {
  inserted(el, binding) {
    const userinfo= JSON.parse(localStorage.getItem('nbcUserInfo')) 
    if (
      userinfo != null &&
      userinfo.UserAccount == "admin"
    ) {
      console.log(1234)
      return true;
    }

    var hasPer = false;
    const value = moudle[binding.value];
    console.log(value)
    if (value == null || value == "") {
      
      hasPer = false;
    } else {
      const permissions = JSON.parse(localStorage.getItem("userresource"));
      if (permissions && permissions.length > 0) {
        hasPer = permissions.some((permission) => {
          return value.toLowerCase() === permission.toLowerCase();
        });
      }
    }

    if (!hasPer) {
      el.parentNode && el.parentNode.removeChild(el);
    }
  },
});
